<template>
    <el-container class="home-container">
        <!-- 头部区域 -->
        <el-header>
            <div>
                <img src="../assets/1.png">
                <span>医无忧后台管理系统</span>
            </div>
            <el-button type="info" @click="logout">退出</el-button>
        </el-header>
        <!-- 页面主体区域 -->
        <el-container>
            <!-- 侧边栏 -->
            <el-aside width="200px">
                <!-- 菜单 -->
                <el-menu
                :default-active="activePath"
                router
                unique-opened
                background-color="#78caa1"
                text-color="#fff"
                active-text-color="#ffd04b">
                    <!-- 一级菜单 -->
                    <el-submenu :index="item.path" v-for="item in menulist" :key="item.id">
                        <template slot="title">
                            <!-- 图标 -->
                            <i :class="iconObj[item.id]"></i>
                            <!-- 名称 -->
                            <span>{{item.authName}}</span>
                        </template>
                        <!-- 二级菜单 -->
                        <el-menu-item :index="subItem.path" v-for="subItem in item.children" :key="subItem.id" @click="saveNavState(subItem.path)">
                            <template slot="title">
                                <i class="el-icon-menu"></i>
                                <span>{{subItem.authName}}</span>
                            </template>
                        </el-menu-item>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <!-- 右侧主体 -->
            <el-main><router-view></router-view></el-main>
        </el-container>
    </el-container>
</template>

<script>
// 导入定义的左侧菜单数据
import { menuList, iconObj } from '../assets/const/data.js'
export default {
  created () {
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  data () {
    return {
      // 左侧菜单数据
      menulist: menuList,
      // icon图标
      iconObj,
      // 被激活的链接地址
      activePath: ''
    }
  },
  methods: {
    logout () {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    // 保存链接的激活状态
    saveNavState (path) {
      window.sessionStorage.setItem('activePath', path)
      this.activePath = path
    }
  }
}
</script>

<style lang="less" scoped>
.home-container{
    height: 100%;
}
.el-header{
    background-color: #71b894;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    font-size: 21px;
    div{
        height: 100%;
        display: flex;
        align-items: center;
        img{
            height: 100%;
            padding-right: 16px;
        }
    }
}
.el-aside{
    background-color: #78caa1;
    .el-menu{
        border-right: 0;
    }
}
.el-main{
    background-color: #eaedf1;
}
</style>
